#!/usr/bin/env bash

. "$GVM_ROOT/scripts/functions"

[[ -d $GVM_ROOT/.git ]] || mv "$GVM_ROOT/git.bak" "$GVM_ROOT/.git" &> /dev/null ||
	display_fatal "Couldn't find git info"

builtin cd "$GVM_ROOT"

if [[ -n $1 ]]; then
  git checkout "$1" -f || display_fatal "Failed to checkout $1 branch"
else
  git checkout -f || display_fatal "Failed to clean install"
fi

git pull || display_fatal "Failed to update"

mv ".git" "git.bak" || display_fatal "Couldn't backup git info"
